<?php

namespace App\Http\Controllers\Api\v1;

use App\common;
use App\Http\Controllers\Controller;
use App\Logic\HouseLogic;
use App\Logic\HouseReLogic;
use app\Logic\RealEstatesLogic;
use App\Models\Administrator;
use Illuminate\Http\Request;


class HouseController extends Controller
{
    /**
     * @name  wl
     * 显示房屋信息
     * @return array|false|string
     */
    public function houseShow(Request $request)
    {
        if ($request->method() != 'GET') {
            return common::fail('', '', '请求方式不正确');
        } else {
            try {
                $house = HouseLogic::HouseShow();
                return common::success('20000', $house, '展示成功');
            } catch (\Exception $exception) {
                return common::fail($exception->getMessage());
            }
        }
    }


    /**
     * @function 详情数据
     * @param Request $request
     */
    public function houseDeaTe(Request $request)
    {
        $id = $request->get('id');
        if (empty($id)) {
            common::fail(50000, [], '参数为空');
        }
        $logicHouse = HouseLogic::houseDeaTeLogic($id);
        return common::success(20000, $logicHouse, '详情数据已查到');
    }


    /**
     * @function 删除方法
     * @param Request $request
     * @return array|false|string
     */
    public function houseDel(Request $request)
    {
        if ($request->method() != 'GET') {
            return common::fail('', '', '请求方式不正确');
        } else {
            try {
                $id = $request->get('id');
                $delLogic = HouseLogic::del($id);
                if ($delLogic) return common::success('20000', $delLogic, '删除成功');
            } catch (\Exception $exception) {
                return common::fail('', "", $exception->getMessage());
            }
        }
    }

    /**
     * @function 搜索方法
     * @param Request $request
     * @return Administrator[]|array|false|\Illuminate\Database\Eloquent\Collection|string
     */
    public static function houseSearch(Request $request)
    {
        if ($request->method() != 'POST') {
            return common::fail('', '', '请求方式不正确');
        } else {
            $message = $request->post('search');
            $result = HouseLogic::searchFunction($message);
            return $result;
        }
    }

    /**
     * @function 修改方法
     * @param Request $request
     * @return array|false|string
     */
    public function houseUpdate(Request $request)
    {
        try {
            $data = $request->all();
            $updateLogic = HouseLogic::HouseUpdate($data);
            if (!$updateLogic) return common::success(20000, $updateLogic, '修改成功');
        } catch (\Exception $exception) {
            return common::fail($exception->getMessage());
        }
    }


    /**
     * @name wl
     * @function 楼盘人气排行
     */
    public function houseController()
    {
        $realEstatesLogic = HouseReLogic::listReal();
        return $realEstatesLogic;
    }


    /**
     *
     * @function  房东列表展示
     */
    public function houseList(Request $request)
    {
        if ($request->method() != 'GET') {
            return common::fail('', '', '请求方式不正确');
        } else {
            try {
                $houseLogic = HouseReLogic::realList();
                return common::success(20000, $houseLogic, '数据已查到');
            } catch (\Exception $exception) {
                return common::fail('', '服务异常', $exception->getMessage());
            }
        }
    }


    /**
     * @function 房屋上架人工审核
     * @param Request $request
     */
    public function houseAuth(Request $request)
    {
        if ($request->method() != 'GET') {
            return common::fail('', '', '请求方式不正确');
        } else {

        }
    }


    /**
     * @function 查看
     *
     * @param Request $request
     */
    public function lookHouse(Request $request)
    {
        if ($request->method() != 'POST') {
            return common::fail('', '', '请求方式不正确');
        } else {
            try {
                $startTime = $request->post('startTime');
                $HouseLogic = HouseLogic::openHome($startTime);
                return common::success(20000, $HouseLogic, '数据已查到');
            } catch (\Exception $exception) {
                return common::fail('', '', $exception->getMessage());
            }
        }
    }


    /**
     *
     * @function  小区列表
     */
    public function estateHouse()
    {

    }

}
